﻿
(function () {
    'use strict';
    var serviceId = 'signalRConnection';
    angular.module('app').factory(serviceId, [signalRConnection]);

    function signalRConnection() {
        var service = {
            connect: connect
        };

        return service;

        function connect() {
            var imageUpload = $.connection.imageHub;

            // Turn logging on so we can see the calls in the browser console
            //$.connection.hub.logging = true;

            // Change the hub url to point to the remote server
            $.connection.hub.url = 'http://localhost:2664/signalr';

            //reseve message from server
            imageUpload.client.sendImages = function (image) {
                // console.log(image);
                var str = image.ImageBytes;
                var newImage = '<img  alt="Embedded Image" width="100" height="80" src="data:image/png;base64,' + str + '" />';
                $("#images").append(newImage);
            };

            //Start connection//  IMPORTANT on server and client ({ jsonp: true })
            $.connection.hub.start({ jsonp: true }).done(function () {
                console.log("connection strated");
            });

        };

    }
})();
